package com.jinunn.system.controller;

import com.jinunn.system.common.enums.LogModuleEnum;
import com.jinunn.system.common.result.Result;
import com.jinunn.system.model.params.DeptParam;
import com.jinunn.system.model.query.DeptQuery;
import com.jinunn.system.model.vo.dept.DeptVO;
import com.jinunn.system.plugin.syslog.annotation.LogAnnotation;
import com.jinunn.system.service.DeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jindun
 * @version DeptController.java, v0.1 2024年 07⽉ 12⽇  下午3:10 Jindun Exp $
 */
@Tag(name = "部门管理")
@RestController
@RequestMapping("/api/v1/dept")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DeptController {

    private final DeptService deptService;

    @Operation(summary = "部门列表")
    @PostMapping("/list")
    @LogAnnotation( value = "部门列表",module = LogModuleEnum.DEPT)
    public Result<List<DeptVO>> getDeptList(@RequestBody @Validated DeptQuery queryParams) {
        List<DeptVO> list = deptService.getDeptList(queryParams);
        return Result.success(list);
    }

    @Operation(summary = "新增部门")
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPerm('sys:dept:add')")
    public Result<Long> saveDept(@RequestBody @Validated DeptParam formData) {
        Long id = deptService.saveDept(formData);
        return Result.success(id);
    }
}
